package com.tcl.netflixhystrix.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.tcl.api.request.UserAddRequest;
import com.tcl.api.response.UserResponse;
import com.tcl.netflixhystrix.feign.UserServiceFeignClient02;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/demo02")
public class DemoController02 {

    @Autowired
    private UserServiceFeignClient02 userServiceFeignClient;

    @GetMapping("/test01")
    @HystrixCommand(fallbackMethod = "fallback")
    public UserResponse test01() {
        return userServiceFeignClient.get(1);
    }

    public UserResponse fallback(Throwable throwable) {
        System.err.println(throwable);
        return new UserResponse();
    }

    @GetMapping("/test02A")
    public List<UserResponse> test02A() {
        return userServiceFeignClient.list("你猜", null);
    }


    @GetMapping("/test03")
    public Integer test03() {
        UserAddRequest userAddRequest = new UserAddRequest();
        userAddRequest.setName("nnnn");
        return userServiceFeignClient.add(userAddRequest);
    }

}
